import { router } from '../main'
import { GetSongUrlAsync, GetSongUrlAsync2 } from 'api/song'
import { STORAGE_THEMES } from 'common/js/constant'

export default {
  change_state ({ commit }, { key, value }) {
    commit('CHANGE_STATE', { key, value })
  },
  setTheme ({ commit }, theme) {
    if (['white', 'black'].includes(theme)) {
      document.getElementById('Themes').href = `static/themes/${theme}.css`
      localStorage.setItem(STORAGE_THEMES, theme)
      commit('CHANGE_STATE', { key: 'Themes', value: theme })
    }
  },

  setDisc ({ commit }, data) {
    if (data.type && data.id) {
      commit('SET_DISC', data)
      router.push('/playlist')
    } else {
      console.log('歌单信息有误！', data)
    }
  },

  setDebug ({ commit, dispatch }, value) {
    // eslint-disable-next-line no-undef
    value ? eruda.init() : eruda.destroy()
    dispatch('change_state', { key: 'debug', value })
  },

  /* 获取歌曲 url */
  GetSongUrlAsync: ({ commit, state }, ids = []) => GetSongUrlAsync(state.settings.BitRate, ids),

  GetSongUrlAsync2: ({ commit, state }, ids = []) => GetSongUrlAsync2(state.settings.BitRate, ids)

}
